package com.itheima.domain;

public class Student implements Comparable<Student>{


    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        //调用者   需要放进去的元素
        //o 已经在集合中元素
        //原有一个28  现在想把25放进去   升序   this- 传进来的对象  降序 o-this
        //25-28
        int result = this.age - o.age;
        //增加比较名字 规则
       /* if(result==0){
            result = this.name.compareTo(o.getName());
            return result;
        }{
            return result;
        }
        */
       result=   result==0?this.name.compareTo(o.getName()):result;
       return result;

    }
}
